﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WidgetLibrary
{
    public static class Helper
    {
        private static string[] _separator = { "/" };
        private static string[] _separator2 = { "." };

        /// <summary>
        /// Get a file extension from url
        /// </summary>
        /// <param name="url">url to get the file extension</param>
        /// <returns>TypeFile</returns>
        public static TypeFileEnum GetFileExtension(string url)
        {
            string[] urlseparated = url.Split(_separator, StringSplitOptions.None);
            string file = urlseparated[urlseparated.Length - 1];
            string[] extension = file.Split(_separator2, StringSplitOptions.None);

            string type = extension[1];

            if (type == "jpg" || type == "jpeg" || type == "bmp" || type == "png")
                return TypeFileEnum.IMAGE;
            if (type == "mp3" || type == "wma" || type == "wav")
                return TypeFileEnum.AUDIO;
            else
                return TypeFileEnum.Unknown;
        }

        /// <summary>
        /// Get a file name from url
        /// </summary>
        /// <param name="url">url to get the file name</param>
        /// <returns>string</returns>
        public static string GetFileName(string url)
        {
            string[] urlseparated = url.Split(_separator, StringSplitOptions.None);
            string file = urlseparated[urlseparated.Length - 1];
            string[] extension = file.Split(_separator2, StringSplitOptions.None);
            return extension[0];
        }
    }
}
